<html>
<head><meta charset="utf-8"><title>what happened to #[repr(C)] · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html">what happened to #[repr(C)]</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="156575249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156575249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156575249">(Jan 22 2019 at 03:03)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="cp">#[repr(C)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">X</span><span class="p">;</span><span class="w"></span>

<span class="cp">#[repr(C)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Y</span><span class="p">(</span><span class="nb">String</span><span class="p">);</span><span class="w"></span>
</pre></div>


<p>Neither of these raise any warnings. I swear at one point they did. What happened to the warnings?</p>



<a name="156588188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156588188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156588188">(Jan 22 2019 at 08:28)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> are you sure? seems like 1.0 didn't warn either: <a href="https://godbolt.org/z/-3K_fL" target="_blank" title="https://godbolt.org/z/-3K_fL">https://godbolt.org/z/-3K_fL</a></p>



<a name="156588259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156588259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156588259">(Jan 22 2019 at 08:29)</a>:</h4>
<p>Yeah, the lint only fires if such a type is used in a function signature imported from C (not even when you define a <code>extern fn</code> in Rust)</p>



<a name="156606146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156606146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156606146">(Jan 22 2019 at 14:11)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span>  I'm never sure about anything.</p>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> :-(</p>



<a name="156606158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156606158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156606158">(Jan 22 2019 at 14:11)</a>:</h4>
<p>thanks</p>



<a name="156634802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156634802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156634802">(Jan 22 2019 at 20:04)</a>:</h4>
<p><code>#[repr(C)]</code> is useful if you want a specific layout, even if that layout is not technically compatible with C</p>



<a name="156635997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156635997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156635997">(Jan 22 2019 at 20:20)</a>:</h4>
<p>Ugh, now I remember this argument (which I see, but feel it's missing the forest for the trees)</p>



<a name="156636051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636051">(Jan 22 2019 at 20:21)</a>:</h4>
<p>Ditto about <code>extern "C"</code> functions...</p>



<a name="156636054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636054">(Jan 22 2019 at 20:21)</a>:</h4>
<p>How do I make the compiler help prevent me and random people asking questions on Stack Overflow from shooting themselves in the foot then?</p>



<a name="156636064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636064">(Jan 22 2019 at 20:21)</a>:</h4>
<p>or <code>extern "anything"</code>, really</p>



<a name="156636124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636124">(Jan 22 2019 at 20:22)</a>:</h4>
<p>Which is something that the Rust compiler in generally lauded for</p>



<a name="156636169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636169">(Jan 22 2019 at 20:23)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> I do not understand how people come to <em>any</em> conclusion about layout of types which have no layout specified and fields of which are private?</p>



<a name="156636188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636188">(Jan 22 2019 at 20:23)</a>:</h4>
<p>Rather seems like there should have been <code>#[repr(not-C-but-im-special)]</code></p>



<a name="156636215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636215">(Jan 22 2019 at 20:23)</a>:</h4>
<p>arguably yes, but it's far too late to introduce that and demand people use it</p>



<a name="156636276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636276">(Jan 22 2019 at 20:24)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> I'm not sure I follow your argument.</p>



<a name="156636335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636335">(Jan 22 2019 at 20:25)</a>:</h4>
<p>I would expect that the majority of people who type <code>extern "C" fn</code> actually want to integrate that function with C (or something else using the C ABI). Thus if a type is present that cannot be validly put into such an ABI, I'd hope the compiler would tell me.</p>



<a name="156636444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636444">(Jan 22 2019 at 20:26)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> What I’m trying to say, that something like <code>extern "C" id(x: *mut MyReprCStructWithUndefinedInternalLayout) -&gt; *mut MyReprCStructWithUndefinedInternalLayout</code> is still very much valid code that is hard to get wrong. But since you don’t know the layout of that struct you cannot write an equivalent typedef in C, and that is fine.</p>



<a name="156636476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636476">(Jan 22 2019 at 20:26)</a>:</h4>
<p>my question is, if people are trying to interface with this struct, how do they figure out what the C type definition should look like at all?</p>



<a name="156636478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636478">(Jan 22 2019 at 20:27)</a>:</h4>
<p>that seems like an obvious first roadblock</p>



<a name="156636510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636510">(Jan 22 2019 at 20:27)</a>:</h4>
<p>like you cannot just write <code>typedef struct { field: String } MyReprCStructWithUndefinedLayout</code>, right?</p>



<a name="156636572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636572">(Jan 22 2019 at 20:28)</a>:</h4>
<p>Here's the concrete case that made me ask. Someone had the moral equivalent of <code>extern "C" fn foo() -&gt; (TcpListener, TcpStream)</code>. The compiler allows this quite happily. This seems extremely poor.</p>



<a name="156636608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636608">(Jan 22 2019 at 20:29)</a>:</h4>
<p>now, if there was a lint that said "hey, you are returning a non-repr(C) struct, probs not what you want", that would have saved them (or we could ask them why they ignored the warning)</p>



<a name="156636738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636738">(Jan 22 2019 at 20:30)</a>:</h4>
<p>right, and nobody can bind to that function either way, because you simply cannot declare <code>TcpListener</code> or <code>TcpStream</code> over FFI. Now the story is quite different for when you have your own non-repr(C) structs that contain entirely primitives and are used in such extern "C" functions.</p>



<a name="156636749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636749">(Jan 22 2019 at 20:30)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> in this case, it's hard to tell because the code was reduced, but they were basically just passing it back to Rust later</p>
<div class="codehilite"><pre><span></span><span class="k">extern</span> <span class="kt">int</span> <span class="nf">foo</span><span class="p">();</span>

<span class="kt">void</span> <span class="nf">example</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="p">{</span>
    <span class="kt">int</span> <span class="n">x</span> <span class="o">=</span> <span class="n">foo</span><span class="p">();</span>
    <span class="c1">// ...</span>
    <span class="n">bar</span><span class="p">(</span><span class="n">x</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>



<a name="156636795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636795">(Jan 22 2019 at 20:31)</a>:</h4>
<p>So they had an "opaque handle" (that somehow worked, they claimed)</p>



<a name="156636834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636834">(Jan 22 2019 at 20:31)</a>:</h4>
<p>I’m not sure how any sort of lint could have helped with this mistake.</p>



<a name="156636901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636901">(Jan 22 2019 at 20:32)</a>:</h4>
<p>I'm... speechless, I guess.</p>



<a name="156636927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636927">(Jan 22 2019 at 20:32)</a>:</h4>
<p>Even if we <em>had</em> lint that said something about returning a non-<code>repr(C)</code> struct, there’s no way to lint against people having a mismatched declaration on the other side of FFI</p>



<a name="156636961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636961">(Jan 22 2019 at 20:33)</a>:</h4>
<p>Yes, there are always times where people can get it wrong, that's why it's a warning / suggestion</p>



<a name="156636977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636977">(Jan 22 2019 at 20:33)</a>:</h4>
<p>(note that I’m not arguing against adding such a lint, I’m just trying to understand how such a mistake could’ve been arrived at at all)</p>



<a name="156636988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156636988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156636988">(Jan 22 2019 at 20:33)</a>:</h4>
<p>rustc sez: "hey, it's literally impossible to access this type in the C ABI"</p>



<a name="156637010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637010">(Jan 22 2019 at 20:33)</a>:</h4>
<p>this sparks the brain</p>



<a name="156637088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637088">(Jan 22 2019 at 20:34)</a>:</h4>
<p>we have lints for far less "meaningful" mistakes (e.g. all the snake_case stuff that I love)</p>



<a name="156637116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637116">(Jan 22 2019 at 20:34)</a>:</h4>
<blockquote>
<p>hey, it's literally impossible to access this type in the C ABI</p>
</blockquote>
<p>It is if the declaration and definition of the function <em>matches</em> (e.g. Rust code both declares and defines the same function with the same signature).</p>



<a name="156637160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637160">(Jan 22 2019 at 20:35)</a>:</h4>
<p>Unclear what you mean: It is ... possible? impossible?</p>



<a name="156637263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637263">(Jan 22 2019 at 20:36)</a>:</h4>
<p>It is possible to have <code>extern "C"</code> function to work with non-repr(C) return types and arguments. All <code>extern "C"</code> changes is how the arguments and return types are passed around. As long as expectations on both the caller and callee side match up, everything will work well, and there are reasonable use-cases for doing so (e.g. dynamically loaded libraries).</p>



<a name="156637299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637299">(Jan 22 2019 at 20:37)</a>:</h4>
<p>we lint against that, because the common use-case is to interface with another language, and dynamic loading is a secondary use-case.</p>



<a name="156637300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637300">(Jan 22 2019 at 20:37)</a>:</h4>
<p>that is fine.</p>



<a name="156637306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637306">(Jan 22 2019 at 20:37)</a>:</h4>
<blockquote>
<p>there are reasonable use-cases</p>
</blockquote>
<p>I definitely am not arguing against that. That's what <code>allow</code> is for</p>



<a name="156637360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637360">(Jan 22 2019 at 20:38)</a>:</h4>
<blockquote>
<p>we lint against that</p>
</blockquote>
<p>Wait... what <strong>do</strong> we lint against?</p>



<a name="156637390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637390">(Jan 22 2019 at 20:38)</a>:</h4>
<p>We lint against using non-<code>repr(C)</code> in function signatures.</p>



<a name="156637429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637429">(Jan 22 2019 at 20:39)</a>:</h4>
<p><a href="https://play.integer32.com/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=dbb3a68b886ca78f97d80a7f0de63dd7" target="_blank" title="https://play.integer32.com/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=dbb3a68b886ca78f97d80a7f0de63dd7">we do not</a></p>
<div class="codehilite"><pre><span></span><span class="k">extern</span><span class="w"> </span><span class="s">&quot;C&quot;</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nb">String</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">String</span>::<span class="n">new</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<div class="codehilite"><pre><span></span>   Compiling playground v0.0.1 (/playground)
warning: function is never used: `foo`
 --&gt; src/lib.rs:1:1
  |
1 | extern &quot;C&quot; fn foo() -&gt; String {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.49s
</pre></div>



<a name="156637494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637494">(Jan 22 2019 at 20:40)</a>:</h4>
<p>wait, what do we lint against then lol.</p>



<a name="156637513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637513">(Jan 22 2019 at 20:40)</a>:</h4>
<p>/me rattles their head</p>



<a name="156637520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637520">(Jan 22 2019 at 20:40)</a>:</h4>
<p>And now we are cycling back to my original point <span class="emoji emoji-1f609" title="wink">:wink:</span></p>



<a name="156637535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637535">(Jan 22 2019 at 20:40)</a>:</h4>
<p>But thank you for pointing out that it it (was?) only on functions.</p>



<a name="156637553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637553">(Jan 22 2019 at 20:41)</a>:</h4>
<p>That is certainly a piece I was missing.</p>



<a name="156637570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637570">(Jan 22 2019 at 20:41)</a>:</h4>
<p>we lint against <code>extern "C" { fn foo(x: String); }</code></p>



<a name="156637590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637590">(Jan 22 2019 at 20:41)</a>:</h4>
<p>which makes sense because we are about 100% sure this function is being imported across FFI.</p>



<a name="156637680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637680">(Jan 22 2019 at 20:42)</a>:</h4>
<p>We should perhaps lint against defining functions like that, with perhaps a lint that is different from the current one.</p>



<a name="156637687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637687">(Jan 22 2019 at 20:42)</a>:</h4>
<p>the uncertainty with the existing lint would be host process functions in a DLL, presumably?</p>



<a name="156637724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637724">(Jan 22 2019 at 20:43)</a>:</h4>
<p>I do not think we should lint against <code>#[repr(C)]</code> structs, though. Mostly because a programmer would notice this either way by trying to declare a compatible type on the other side of the FFI.</p>



<a name="156637751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637751">(Jan 22 2019 at 20:43)</a>:</h4>
<p>Yeah, I'd be cool with that line in the sand as well.</p>



<a name="156637792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637792">(Jan 22 2019 at 20:44)</a>:</h4>
<p>I agree. I have actually previously argued for linting <code>improper_ctypes</code> in Rust-defined <code>#[no_mangle] extern "C"</code> functions. There was an issue about it, let me find it.</p>



<a name="156637846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637846">(Jan 22 2019 at 20:44)</a>:</h4>
<p>although I wish that there had been the "other" repr that wasn't conflicted meaning</p>



<a name="156637865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637865">(Jan 22 2019 at 20:45)</a>:</h4>
<p>Clearly we need a <code>repr(cdylib)</code> analog ;-)</p>



<a name="156637875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637875">(Jan 22 2019 at 20:45)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/19834" target="_blank" title="https://github.com/rust-lang/rust/issues/19834">https://github.com/rust-lang/rust/issues/19834</a></p>



<a name="156637963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637963">(Jan 22 2019 at 20:46)</a>:</h4>
<p>/me looks at their comment in the linked issue.</p>



<a name="156637973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637973">(Jan 22 2019 at 20:46)</a>:</h4>
<p>Some jerk named "nagisa" shot it down, I see.</p>



<a name="156637978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156637978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156637978">(Jan 22 2019 at 20:46)</a>:</h4>
<p><span class="emoji emoji-1f923" title="rolling on the floor laughing">:rolling_on_the_floor_laughing:</span></p>



<a name="156638018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156638018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156638018">(Jan 22 2019 at 20:47)</a>:</h4>
<p>Though it was exactly everybody’s position at the time: no-false-positives in rustc, rest in clippy</p>



<a name="156638044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156638044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156638044">(Jan 22 2019 at 20:47)</a>:</h4>
<p>not sure whether it has changed yet, but it quite likely that it hasn’t.</p>



<a name="156638050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156638050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156638050">(Jan 22 2019 at 20:47)</a>:</h4>
<p>I'm going to take a screenshot of your comment here saying it should exist and just post it with no commentary.</p>



<a name="156638072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156638072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156638072">(Jan 22 2019 at 20:47)</a>:</h4>
<p><em>no</em> false positives seems overly strong.</p>



<a name="156638139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156638139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156638139">(Jan 22 2019 at 20:48)</a>:</h4>
<p>But certainly a very low rate, absolutely.</p>



<a name="156638155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156638155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156638155">(Jan 22 2019 at 20:48)</a>:</h4>
<p>Right, because <code>extern "C" { fn ... }</code> is also not quite 100% false-positive free.</p>



<a name="156638716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156638716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156638716">(Jan 22 2019 at 20:55)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> dug up a <a href="https://github.com/rust-lang/rust/issues/36464" target="_blank" title="https://github.com/rust-lang/rust/issues/36464">https://github.com/rust-lang/rust/issues/36464</a></p>



<a name="156638908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156638908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156638908">(Jan 22 2019 at 20:58)</a>:</h4>
<p>well you linked to it from the other one^^</p>



<a name="156693057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156693057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156693057">(Jan 23 2019 at 14:34)</a>:</h4>
<p>One way to pass semi-C, semi-Rust structures across C is this (I just thought of it)</p>
<div class="codehilite"><pre><span></span><span class="cp">#[repr(C)]</span><span class="w"> </span><span class="k">struct</span> <span class="nc">That</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">foo</span>: <span class="nc">c_int</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">bar</span>: <span class="nc">c_banana</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">qux</span>: <span class="nb">String</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">extern</span><span class="w"> </span><span class="s">&quot;C&quot;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="w"> </span><span class="p">(</span><span class="n">that</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="n">That</span><span class="p">);</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div>


<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="n">that</span> <span class="p">{</span>
     <span class="kt">int</span> <span class="n">foo</span><span class="p">;</span>
     <span class="n">banana</span> <span class="n">bar</span><span class="p">;</span>
     <span class="kt">uint8_t</span> <span class="n">rest</span><span class="p">[];</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="n">foo</span><span class="p">(</span><span class="k">const</span> <span class="k">struct</span> <span class="n">that</span><span class="o">*</span> <span class="n">that</span><span class="p">)</span> <span class="p">{</span> <span class="p">...</span> <span class="p">}</span>
</pre></div>



<a name="156693315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/156693315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#156693315">(Jan 23 2019 at 14:37)</a>:</h4>
<p>seems very fine to me as long as nobody attempts to interpret <code>rest</code> in any way.</p>



<a name="157400569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/157400569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Peter Rabbit <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#157400569">(Feb 02 2019 at 01:20)</a>:</h4>
<p>My opinion stated in that issue hasn't changed. Please lint on non C compatible types in <code>extern "C"</code> signatures.</p>



<a name="157438657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/157438657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#157438657">(Feb 02 2019 at 21:11)</a>:</h4>
<p><span class="user-mention" data-user-id="125267">@Peter</span> don't we?</p>



<a name="157438658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/157438658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#157438658">(Feb 02 2019 at 21:11)</a>:</h4>
<p>what issue?</p>



<a name="157438666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/157438666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Peter Rabbit <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#157438666">(Feb 02 2019 at 21:12)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/36464" target="_blank" title="https://github.com/rust-lang/rust/issues/36464">https://github.com/rust-lang/rust/issues/36464</a></p>



<a name="157438691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/157438691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#157438691">(Feb 02 2019 at 21:12)</a>:</h4>
<p>oh, I see</p>



<a name="157438710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/157438710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#157438710">(Feb 02 2019 at 21:12)</a>:</h4>
<p>yeah I agree</p>



<a name="157439054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/what%20happened%20to%20%23%5Brepr%28C%29%5D/near/157439054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/what.20happened.20to.20.23.5Brepr(C).5D.html#157439054">(Feb 02 2019 at 21:22)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> you can also just do:</p>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="n">s</span>: <span class="nb">String</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">x</span>: <span class="kt">i32</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">y</span>: <span class="kt">i32</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">extern</span><span class="w"> </span><span class="s">&quot;C&quot;</span><span class="w"> </span><span class="k">fn</span> <span class="nf">make_Foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nb">Box</span><span class="o">&lt;</span><span class="n">Foo</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>

<span class="k">extern</span><span class="w"> </span><span class="s">&quot;C&quot;</span><span class="w"> </span><span class="k">fn</span> <span class="nf">get_x</span><span class="p">(</span><span class="n">f</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">Foo</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="kt">i32</span><span class="p">;</span><span class="w"></span>
</pre></div>


<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="n">Foo</span><span class="p">;</span>

<span class="k">struct</span> <span class="n">Foo</span><span class="o">*</span> <span class="nf">make_Foo</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
<span class="kt">int</span><span class="o">*</span> <span class="nf">get_x</span><span class="p">(</span><span class="k">struct</span> <span class="n">Foo</span> <span class="k">const</span><span class="o">*</span> <span class="n">f</span><span class="p">);</span>
</pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>